﻿

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Text;

public class BLL_tbl_purchase_order
{
    public BLL_tbl_purchase_order()
    {

    }

    public List<tbl_purchase_order> select(int PO_ID)
    {
        DAL_tbl_purchase_order dal = new DAL_tbl_purchase_order();
        return dal.select(PO_ID);
    }

    public List<tbl_purchase_order> select(string Po_number)
    {
        DAL_tbl_purchase_order dal = new DAL_tbl_purchase_order();
        return dal.selectOrderNumber(Po_number);
    }

   

    public DataTable selectAll()
    {
        DAL_tbl_purchase_order dal = new DAL_tbl_purchase_order();
        return dal.selectAll();
    }

    public bool insert(tbl_purchase_order tbl)
    {
        DAL_tbl_purchase_order dal = new DAL_tbl_purchase_order();
        int i = 0;
        i = dal.insert(
            tbl.PO_ID
, tbl.USER_CODE
, tbl.PURCHASE_ORDER_NO
, tbl.IS_SAMPLE
, tbl.SUB_PRODUCT_ID
, tbl.QUANTITY
, tbl.PRICE_PER_KG
, tbl.PAYMENT_TERM_ID
, tbl.DELIVERY_DATE
, tbl.PARTIAL_PAYMENT
, tbl.SHIPPING_ID
, tbl.SHIPPING_TERMS_ID
, tbl.PRODUCTION_RELESE_DATE
, tbl.CREATED_DATE
, tbl.CREATED_BY
, tbl.ACCEPTED_BY
, tbl.ACCEPTED_DATE,tbl.currencyID
        );

        return Convert.ToBoolean(i);
    }

    public bool update(tbl_purchase_order tbl)
    {
        DAL_tbl_purchase_order dal = new DAL_tbl_purchase_order();
        int i = 0;
        i = dal.update(
            tbl.PO_ID
, tbl.USER_CODE
, tbl.PURCHASE_ORDER_NO
, tbl.IS_SAMPLE
, tbl.SUB_PRODUCT_ID
, tbl.QUANTITY
, tbl.PRICE_PER_KG
, tbl.PAYMENT_TERM_ID
, tbl.DELIVERY_DATE
, tbl.PARTIAL_PAYMENT
, tbl.SHIPPING_ID
, tbl.SHIPPING_TERMS_ID
, tbl.PRODUCTION_RELESE_DATE
, tbl.ACCEPTED_BY
, tbl.ACCEPTED_DATE
, tbl.UPDATED_BY
, tbl.UPDATED_DATE
, tbl.currencyID
            );

        return Convert.ToBoolean(i);
    }

    public int appprovePo(int PoID, string userCode)
    {
        DAL_tbl_purchase_order dal = new DAL_tbl_purchase_order();
        return dal.ApprovePo(PoID, userCode);
    }

    public bool delete(tbl_purchase_order tbl)
    {
        DAL_tbl_purchase_order dal = new DAL_tbl_purchase_order();
        int i = 0;
        i = dal.delete(
                tbl.PO_ID
        );

        return Convert.ToBoolean(i);
    }

    public DataTable GetProducts()
    {
        DAL_tbl_purchase_order dal = new DAL_tbl_purchase_order();
        try
        {

            return dal.GetProducts();
        }
        catch (Exception)
        {

            throw;
        }
        finally { dal = null; }
    }

    public DataTable GetClients()
    {
        DAL_tbl_purchase_order dal = new DAL_tbl_purchase_order();
        try
        {

            return dal.GetClients();
        }
        catch (Exception)
        {

            throw;
        }
        finally { dal = null; }
    }

    public DataTable GetClients(string user_code)
    {
        DAL_tbl_purchase_order dal = new DAL_tbl_purchase_order();
        try
        {

            return dal.GetClients(user_code);
        }
        catch (Exception)
        {

            throw;
        }
        finally { dal = null; }
    }

    public DataTable GetPaymentTerms()
    {
        DAL_tbl_purchase_order dal = new DAL_tbl_purchase_order();
        try
        {

            return dal.GetPaymentTerms();
        }
        catch (Exception)
        {

            throw;
        }
        finally { dal = null; }
    }

    public DataTable GetShippingTerms()
    {
        DAL_tbl_purchase_order dal = new DAL_tbl_purchase_order();
        try
        {

            return dal.GetShippingTerms();
        }
        catch (Exception)
        {

            throw;
        }
        finally { dal = null; }
    }

    public DataTable GetShippingType()
    {
        DAL_tbl_purchase_order dal = new DAL_tbl_purchase_order();
        try
        {

            return dal.GetShippingType();
        }
        catch (Exception)
        {

            throw;
        }
        finally { dal = null; }
    }

    public bool CheckPurchaseOrder(string POrder)
    {
        DAL_tbl_purchase_order dal = new DAL_tbl_purchase_order();
        try
        {

            return dal.CheckPurchaseOrder(POrder);
        }
        catch (Exception)
        {

            return true;
        }
        finally { dal = null; }
    }

    public DataTable FetchPendingApproval()
    {
        DAL_tbl_purchase_order dal = new DAL_tbl_purchase_order();
        try
        {
            DataTable dt = dal.FetchPendingApproval();  

           return dt;

           
        }
        catch (Exception)
        {

            return null;
        }
        finally { dal = null; }
    }

    public DataTable getWorkOrderNum()
    {
        DAL_tbl_purchase_order dal = new DAL_tbl_purchase_order();
        return dal.getWorkOrderNum();
    }

}

